﻿
var localizeContentViewName = '';

$(document).ready(function() {

	$('<div id="translationdialog"></div>').appendTo(document.body);
	$("#translationdialog").dialog({
		show: 'slide',
		hide: 'slide',
		width: 600,
		autoOpen: false,
		bgiframe: true
	});
	$("#translationdialog").css("border", "1px solid red");

	$(".translate").css("border", "1px solid red");

	$('<ul id="translationContextMenu" class="contextMenu"><li class="edit"><a href="#translate">Translate</a></li></ul>').appendTo(document.body);

	$(".translate").contextMenu({ menu: 'translationContextMenu' }
		, function(action, el, pos) {
			var rel = el.attr("rel").split(',');
			$("#translationdialog").load('/localize/content'
					, { key: rel[0], path: rel[1], token: _translation_findParam('translate'), viewName: localizeContentViewName }
					, function(html) {
						$('#translationdialog').empty();
						$("#translationdialog").html(html);
						$("#translationdialog").dialog('open');
					}
			);
		}
	);


	var titleList = $("title^='translate:'");
	$.each(titleList, function() {
		
	});

})


function _translation_findParam(key, url) {
	var currentUrl = "";
	if (!url) {
		currentUrl = document.location.href.split('?');
	}
	else {
		currentUrl = url.split('?');
	}
	var query = currentUrl[1];
	var result = "";
	if (query == null) {
		return result;
	}
	var params = query.split('&');
	for (var i = 0; i < params.length; i++) {
		var param = params[i];
		if (param.indexOf(key) != -1) {
			var val = param.split('=');
			if (val != null) {
				result = val[1];
				break;
			}
		}
	}
	return result;
}